package kuangshen.stasus;

/**
 * @program: liangt
 * @description: 监控线程状态
 * @author: liangt
 * @create: 2021-03-03 13:22
 */
public class TestStatus {

    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("////////////////");
        });

        //就绪状态
        Thread.State state = thread.getState();
        System.out.println(state);

        //启动状态
        thread.start();
        state = thread.getState();
        System.out.println(state);

        while (state != Thread.State.TERMINATED){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            state = thread.getState();
            System.out.println(state);
        }
        state = thread.getState();
        System.out.println(state);
    }
}
